package com.k.liuzh.extraffic.Database;

import android.content.Context;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.QueryBuilder;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class ChongZhiDao {

    private Context context;
    private Dao<ChongZhiBean,Integer> dao;
    private List<ChongZhiBean> result;

    public ChongZhiDao(Context context) {
        this.context = context;
        try {
            this.dao = DatabaseHelper.getInstance(context).getDao(ChongZhiBean.class);
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

    public void add(ChongZhiBean data){
        try {
            dao.create(data);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void del(ChongZhiBean data){
        try {
            dao.delete(data);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void updata(ChongZhiBean data){
        try {
            dao.update(data);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public ChongZhiBean queryByCarId(int carId){
        ChongZhiBean clazz = null;
        try {
            clazz = dao.queryForId(carId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return clazz;
    }
    public List<ChongZhiBean> queryByTimeUp() {
        QueryBuilder<ChongZhiBean, Integer> clazz = null;
        clazz = dao.queryBuilder().orderBy("time",true);
        try {
            List<ChongZhiBean> result = clazz.query();
            return result;
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }

    }

    public List<ChongZhiBean> queryByTimeDown() {
        QueryBuilder<ChongZhiBean, Integer> clazz = null;
        clazz = dao.queryBuilder().orderBy("time",false);
        try {
            List<ChongZhiBean> result = clazz.query();
            return result;
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }

    }

}
